package com.example.jetpack_viewmodel_livedata.sticky;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Observer;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.example.jetpack_viewmodel_livedata.LiveDataBus;
import com.example.jetpack_viewmodel_livedata.R;

public class MainActivity2 extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        LiveDataBus.getInstance().with("start", String.class, false).observe(this, new Observer<String>() {
            @Override
            public void onChanged(String s) {
                Toast.makeText(MainActivity2.this, s, Toast.LENGTH_SHORT).show();
            }
        });
        findViewById(R.id.btnvalue).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        LiveDataBus.getInstance().with("start", String.class, false).postValue("MainActivity2消息2");
                    }
                }).start();
            }
        });
        String start = LiveDataBus.getInstance().with("start", String.class, false).getValue();
        Log.d("print", "start:"+start);

    }

    @Override
    protected void onResume() {
        super.onResume();

    }
}